package com.example.myapp;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

//启动页
public class IndexActivity extends AppCompatActivity {
    private    TextView timeTv ;
    private    int textTime=3;

    private  Handler handler = new Handler();
    private  Runnable runnable = new Runnable() {
        @Override
        public void run() {
            handler.postDelayed(this,1000);//一秒钟循环计时一次
            String s = String.valueOf(textTime);
            timeTv.setText("跳过"+s+"s");
            textTime--;
            //显示时间倒计时
            if (textTime == 0){
                //跳到LoginActivity
                if (!isFinishing()){
                    toLoginActivity();
                }

            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index_layout);
        timeTv = findViewById(R.id.time_tv);
        handler.post(runnable);
        //点击监听
        timeTv.setOnClickListener(view -> {
            //跳到LoginActivity
            toLoginActivity();
        });

    }




    private void toLoginActivity(){
        Intent intent = new Intent(IndexActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }




}